﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //用户名小红密码1234
            
            SqlConnection connection = new SqlConnection("server=.;uid=sa;pwd=1;database=Blogs");

            SqlCommand cmd = new SqlCommand("select * from Users where Username='"
                + textBox1.Text.Trim() + "' and Password='" + textBox2.Text.Trim() + "'", connection);

            if (textBox1.Text == "" || textBox2.Text == "")
                MessageBox.Show("请输入用户名密码");
      
            connection.Open();

            SqlDataReader sdr = cmd.ExecuteReader();
            sdr.Read();
            if (sdr.HasRows)
            {
                MessageBox.Show("登录成功!");
               
                Mainform wh = new Mainform();
                wh.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名或密码错误!");
            }

            connection.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Register re = new Register();
            re.Show();


        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            Form3 form3 = new Form3();
            form3.Show();
        }
    }
}
